<!DOCTYPE html>
<html>

<head>
    <title>Login Example</title>
</head>

<body>
    <form id="loginForm">
        <input type="text" id="username" placeholder="Username">
        <input type="password" id="password" placeholder="Password">
        <button type="button" id="loginButton">Login</button>
    </form>

    <script>
        document.getElementById('loginButton').addEventListener('click', function() {
            var username = document.getElementById('username').value;
            var password = document.getElementById('password').value;

            // 构建发送到服务器的数据
            var data = {
                username: username,
                password: password
            };

            // 通过 Ajax 发送数据到服务器
            var xhr = new XMLHttpRequest();
            // xhr.open('POST', 'http://127.0.0.1:5000/login', true);
            xhr.open('POST', 'http://10.10.80.155:8080/login', true);
            xhr.setRequestHeader('Content-Type', 'application/json');

            xhr.onreadystatechange = function() {
                if (xhr.readyState === 4 && xhr.status === 200) {
                    // 处理服务器返回的数据
                    var response = JSON.parse(xhr.responseText);
                    if (response.success) {
                        // 登录成功
                        parent.window.location.href = "https://wyh2085195880.gitee.io/html5_class_record";
                        console.log(response.message);
                    } else {
                        // 登录失败
                        console.log(response.message);
                    }
                }
            };

            xhr.send(JSON.stringify(data));
        });
    </script>
</body>

</html>